<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <div id="app"></div>

    <template id="my-app">
      <ul>
        <!-- 使用v-for添加key属性后做增删操作，性能更好，这跟Vue虚拟DOM的diff算法有关 -->
        <li v-for="item in letters" :key="item">{{item}}</li>
      </ul>
      <button @click="insertF">插入f元素</button>
    </template>

    <script src="../js/Vue.js"></script>
    <script>
      const app = {
        template: '#my-app',
        data() {
          return {
            letters: ['a', 'b', 'c', 'd']
          }
        },
        methods: {
          insertF() {
            this.letters.splice(2, 0, 'f')
          }
        }
      }

      Vue.createApp(app).mount('#app')
    </script>
  </body>
</html>
